import { ChannelAction } from "../actions/channel";
import { Channel } from './../actions/channel';

// 提供channel默认的数据类型
type ChannelType = {
  channelList: Channel[]
  active: number
}

// 提供初始值的类型
const initValue: ChannelType = {
  channelList: [],
  active: 0
}

//TODO 这里少了一个ChannelType的返回值
export default function channel(state = initValue, action: ChannelAction) {
  switch (action.type) {
    case 'channel/getChannelist':
      return {
        ...state,
        channelList: action.payload
      }
    case 'channel/changeActive':
      return {
        ...state,
        active: action.id
      }
    default:
      return state
  }

}